import * as bm from "/js/baseModule.js";

export class Module extends bm.baseModule {
    constructor(view) {
        super(view);
        let that = this;
        let data = {avatar: globalData.user.avatar,nick:globalData.user.nick,mobile:globalData.user.mobile};
        let dom = this.find('.UpdateSupplierInfo_vue')[0];
        this.vuePane = new Vue({
            el: dom,
            data: { user: data },
            methods: {
                submit: function () {
                    let nick = this.user.nick;
                    let mobile = this.user.mobile;
                    let avatar = this.user.avatar;
                    let userInfo = {
                        nickname: nick,
                    };
                    if (nick && mobile && avatar) {
                        //激活成功则关闭弹窗
                        api.activeSupplier(userInfo,{
                            succ: function () {
                                that._evt_goback();
                                funs.tip('更新个人信息成功', '', 'succ',2000);
                                globalData.user.nick = nick;
                                setTimeout(function () {
                                    // 打开聊天室
                                    // funs.swipeModule('modules/')
                                }, 2020);
                            },
                            fail: function () {
                                funs.tip('更新失败，请重试', '', 'fail');
                            }
                        })
                    }
                },
                addAvatar: function () {
                    //打开上传头像的弹窗
                    funs.openModal('modules/user/AvatarUploader.js',function (mod) {
                        console.log(mod);
                    })
                }
            }
        });
        // 监听名字输入
        this.find('.nickname').on('input', function () {
            let v = $(this).val();
            if (v && v != ' ') {
                that.vuePane.user.nick = v;
                that.checkData();
            } else {
                that.find('.btn').attr('disabled', 'disabled');
            }
        })

    }
    afterInstall(){
        let content = this.config.parent.find('.CenterModalContent');
        let height = content.height();
        content.css('margin-top', -height/2+'px');
        setTimeout(function () {
            content.css({'transform':'scale(1,1)','opacity':'1'});
        },100);
    }
    checkData() {
        let nick = globalData.user.nick;
        let mobile = globalData.user.mobile;
        let avatar = globalData.user.avatar;
        if (nick && mobile && avatar) {
            this.find('.btn').removeAttr('disabled');
        }
    }
    setAvatar(img){
        this.vuePane.user.avatar = img;
        this.checkData();
    }
}
